package ltd.hxya.novel.common.config;

import feign.Request;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import ltd.hxya.novel.common.bean.UserBean;
import ltd.hxya.novel.common.constant.JwtConstant;
import ltd.hxya.novel.common.constant.SecurityConstant;
import ltd.hxya.novel.common.utils.JwtUtils;
import org.apache.kerby.kerberos.provider.token.JwtUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Configuration
public class FeignRequestConfig {

    /**TODO
     * 解决在发送feign时的的鞥路问题
     */
    @Bean
    public RequestInterceptor requestInterceptor(){
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate template) {
//                ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//                if (requestAttributes==null){
//                    //手动添加具有权限的账号
//
//                }
//
//                HttpServletRequest request = requestAttributes.getRequest();
//                String authorization = request.getHeader(JwtConstant.TOKEN_HEADER_KEY);
//                String adminAuthorization = request.getHeader(JwtConstant.TOKEN_HEADER_ADMIN_KEY);
//                if (!StringUtils.isEmpty(authorization)){
//                    template.header(JwtConstant.TOKEN_HEADER_KEY,authorization);
//                }
//                if (!StringUtils.isEmpty(adminAuthorization)){
//                    template.header(JwtConstant.TOKEN_HEADER_ADMIN_KEY,adminAuthorization);
//                }
                template.header(SecurityConstant.IS_AUTHENTICATION,"false");
            }
        };
    }
}
